package com.biodiv.community.controller.mq;

import com.biodiv.community.enums.TopicEnum;
import com.biodiv.community.event.OrderEvent;
import com.biodiv.community.event.UserEvent;
import com.biodiv.community.manager.mq.RedisPublisher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MessageController {

    @Autowired
    private RedisPublisher redisPublisher;

    @Autowired
    private ApplicationEventPublisher eventPublisher;

    @GetMapping("/publish1")
    public String publishMessage() {
        OrderEvent orderEvent = new OrderEvent();
        orderEvent.setOrderId("123");
        orderEvent.setOrderName("Order 123");
        System.out.println("Thread name: " + Thread.currentThread().getName());
        redisPublisher.publish(TopicEnum.TOPIC_TWO, orderEvent);
        return "Message published: ";
    }

    @GetMapping("/publish2")
    public String publishMessage1() {
        UserEvent userEvent = new UserEvent();
        userEvent.setUserName("User 123");
        userEvent.setPassword("<PASSWORD>");
        System.out.println("Thread name: " + Thread.currentThread().getName());
        redisPublisher.publish(TopicEnum.TOPIC_ONE, userEvent);
        return "Message published: ";
    }

}